package com.intellagric.service.iftmonitor.Impl.ift_ctrl_equipment;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.dao.iftmonitor.CtrlEquipmentDao;
import com.intellagric.mapper.IftCtrlEquipmentMapper;
import com.intellagric.module.iftmonitor.CtrlEquipmentVo;
import com.intellagric.pojo.IftCtrlEquipment;
import com.intellagric.pojo.IftCtrlEquipmentExample;
import com.intellagric.service.iftmonitor.ift_ctrl_equipment.CtrlEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/21
 * @DESC： 控制设备服务实现
 */
@Service
public class CtrlEquipmentServiceImpl implements CtrlEquipmentService {

    @Autowired
    private IftCtrlEquipmentMapper ctrlEquipmentMapper;

    @Autowired
    private CtrlEquipmentDao ctrlEquipmentDao;

    /**
     * 添加控制设备信息
     * @param ctrlEquipment
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addCtrlEquipment(IftCtrlEquipment ctrlEquipment) {
        if (ctrlEquipmentMapper.insertSelective(ctrlEquipment) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除控制设备信息
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteCtrlEquipment(String id) {
        if (ctrlEquipmentMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改控制设备信息
     * @param ctrlEquipment
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editCtrlEquipment(IftCtrlEquipment ctrlEquipment) {
        if (ctrlEquipmentMapper.updateByPrimaryKeySelective(ctrlEquipment) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询控制设备信息
     * @param id
     * @return IftCtrlEquipment
     */
    @Override
    public IftCtrlEquipment getCtrlEquipmentById(String id) {
        return ctrlEquipmentMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询控制设备信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentList() {
        IftCtrlEquipmentExample ctrlEquipmentExample = new IftCtrlEquipmentExample();
        ctrlEquipmentExample.createCriteria().andIdIsNotNull();
        List<IftCtrlEquipment> ctrlEquipmentList = ctrlEquipmentMapper.selectByExample(ctrlEquipmentExample);
        return LayuiDataGridResult.success().add(ctrlEquipmentList,ctrlEquipmentList.size());
    }

    /**
     * 多条件查询控制设备信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentListByVo(CtrlEquipmentVo ctrlEquipmentVo) {
        List<IftCtrlEquipment> ctrlEquipmentList = ctrlEquipmentDao.selectCtrlEquipmentListByVo(ctrlEquipmentVo);
        return LayuiDataGridResult.success().add(ctrlEquipmentList,ctrlEquipmentList.size());
    }

    /**
     * 分页查询控制设备信息列表
     * @param page
     * @param rows
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        IftCtrlEquipmentExample ctrlEquipmentExample = new IftCtrlEquipmentExample();
        ctrlEquipmentExample.createCriteria().andIdIsNotNull();
        List<IftCtrlEquipment> ctrlEquipmentList = ctrlEquipmentMapper.selectByExample(ctrlEquipmentExample);

        //查询控制设备对应的按钮列表

        return LayuiDataGridResult.success().add(ctrlEquipmentList,this.getCtrlEquipmentList().getCount());
    }
}
